package com.servlet;

import com.dao.searchdao;
import com.dao.searchdaoimpl;
import com.entity.productdetails;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;

public class searchs extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=utf-8");
        String message=req.getParameter("searchBox1");
        String message1=req.getParameter("searchBox2");
        String message2=req.getParameter("searchBox3");
        searchdao s=new searchdaoimpl();
        Set<productdetails> list = new HashSet<>(s.searchs(message,message1,message2));
        if(s.searchs(message,message1,message2).size()!=0)
        {
            req.getSession().setAttribute("messages",list);
            req.getRequestDispatcher("/sousuotiaozhuan.jsp").forward(req,resp);
        }
        else
        {
            req.getSession().setAttribute("messagess","没有找到相关信息");
            req.getRequestDispatcher("/sousuotiaozhuan.jsp").forward(req,resp);
            req.getSession().setAttribute("messagess","");
        }
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doPost(req, resp);
    }
}
